package cn.amossun.starter.event.handler;

import cn.hutool.core.util.StrUtil;
import cn.amossun.starter.event.annoation.EventExchange;
import cn.amossun.starter.event.annoation.EventListener;
import cn.amossun.starter.event.annoation.EventPublisher;
import cn.amossun.starter.event.enums.DurabilityEnum;
import cn.amossun.starter.event.property.EventExchangeContext;

import java.util.List;
import java.util.Map;

public interface ExchangeContextHolder extends EventContextHolder {

    List<EventExchangeContext> buildEventExchangeContexts(EventListener eventListener);

    EventExchangeContext buildEventExchangeContexts(EventPublisher eventPublisher);

    default EventExchangeContext process(EventExchange eventExchange) {
        if(StrUtil.isEmpty(eventExchange.name()) && StrUtil.isEmpty(eventExchange.value())){
            return null;
        }
        Map<String, Object> argumentsMap = getArguments(eventExchange.arguments());
        EventExchangeContext eventExchangeContext = new EventExchangeContext(
                eventExchange.name(),
                eventExchange.type(),
                eventExchange.durable() ? DurabilityEnum.DURABLE : DurabilityEnum.TRANSIENT,
                eventExchange.autoDelete(),
                eventExchange.internal(),
                argumentsMap
        );
        return eventExchangeContext;
    }

}
